﻿<UserControl x:Class="TanmiaGrp.GeneralLedger.WinApp.Scenarios.GroupEditorView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:Scenarios="clr-namespace:TanmiaGrp.GeneralLedger.WinApp.Scenarios"  
             xmlns:loc="clr-namespace:TanmiaGrp.GeneralLedger.WinApp"
             xmlns:mui="http://firstfloorsoftware.com/ModernUI"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             mc:Ignorable="d"
             d:DesignHeight="500"
             d:DesignWidth="300"
             FlowDirection="RightToLeft">

    <UserControl.Resources>

        <loc:NullToVisibilityConverter x:Key="nullConverter" />

        <ControlTemplate x:Key="ValidationTemplate">
            <StackPanel Orientation="Vertical">
                <Border BorderThickness="1"
                        BorderBrush="#FFdc000c"
                        VerticalAlignment="Top">
                    <Grid>
                        <AdornedElementPlaceholder x:Name="adorner"
                                                   Margin="-1" />
                    </Grid>
                </Border>
                <Border x:Name="errorBorder"
                        Background="#FFdc000c"
                        Opacity="0"
                        CornerRadius="0"
                        IsHitTestVisible="False"
                        MinHeight="20">
                    <TextBlock Text="{Binding ElementName=adorner, Path=AdornedElement.(Validation.Errors)[0].ErrorContent}"
                               Foreground="White"
                               Margin="8,1,8,3"
                               TextWrapping="Wrap"
                               VerticalAlignment="Center" />
                </Border>
            </StackPanel>
            <ControlTemplate.Triggers>
                <DataTrigger Value="True">
                    <DataTrigger.Binding>
                        <Binding ElementName="adorner"
                                 Path="AdornedElement.IsKeyboardFocused" />
                    </DataTrigger.Binding>
                    <DataTrigger.EnterActions>
                        <BeginStoryboard x:Name="fadeInStoryboard">
                            <Storyboard>
                                <DoubleAnimation Duration="00:00:00.15"
                                                 Storyboard.TargetName="errorBorder"
                                                 Storyboard.TargetProperty="Opacity"
                                                 To="1" />
                            </Storyboard>
                        </BeginStoryboard>
                    </DataTrigger.EnterActions>
                    <DataTrigger.ExitActions>
                        <StopStoryboard BeginStoryboardName="fadeInStoryboard" />
                        <BeginStoryboard x:Name="fadeOutStoryBoard">
                            <Storyboard>
                                <DoubleAnimation Duration="00:00:00"
                                                 Storyboard.TargetName="errorBorder"
                                                 Storyboard.TargetProperty="Opacity"
                                                 To="0" />
                            </Storyboard>
                        </BeginStoryboard>
                    </DataTrigger.ExitActions>
                </DataTrigger>
            </ControlTemplate.Triggers>
        </ControlTemplate>

    </UserControl.Resources>

    <Grid>

        <Grid.Resources>
            <Style TargetType="HeaderedContentControl">
                <Setter Property="Focusable"
                        Value="False" />
                <Setter Property="Margin"
                        Value="0,0,0,5" />

            </Style>
        </Grid.Resources>

        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>

        <!-- Header -->
        <DockPanel Grid.Row="0" Height="46">
            <Scenarios:WindowBar x:Name="windowBar" DockPanel.Dock="Left" PopouClicked="OnPopout" />
            <TextBlock Style="{StaticResource CaptionStyle}" 
                       Text="{Binding Path=StateText}" />
            
            <TextBlock DockPanel.Dock="Left" 
                       Text="مجموعة" 
                       Style="{StaticResource CaptionStyle}"  />

            <Scenarios:NewBar HorizontalAlignment="Right" DockPanel.Dock="Right" />
            <Scenarios:SaveBar HorizontalAlignment="Right" />
        </DockPanel>

        <Grid Grid.Row="1">
            <StackPanel Orientation="Vertical">
                <StackPanel.Resources>
                    <Style TargetType="HeaderedContentControl">
                        <Setter Property="Foreground" Value="#ff6e6e6e" />
                        <Setter Property="Focusable" Value="False" />
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="HeaderedContentControl">
                                    <StackPanel Margin="0,0,0,2">
                                        <ContentPresenter ContentSource="Header" Margin="6,0,6,4" />
                                        <ContentPresenter ContentSource="Content" Margin="5,4,5,4" />
                                    </StackPanel>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                    
                </StackPanel.Resources>
                <HeaderedContentControl Header="رقم المجموعة">
                    <TextBox Text="{Binding Path=Entity.GroupID}"
                             IsReadOnly="True" 
                             Height="30" Width="200"
                             VerticalContentAlignment="Center"
                             HorizontalAlignment="Left"/>
                </HeaderedContentControl>

                <HeaderedContentControl Header="اسم المجموعة">
                    <TextBox Text="{Binding Path=Entity.GroupName, ValidatesOnDataErrors=True, NotifyOnValidationError=True, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                             Validation.ErrorTemplate="{StaticResource ValidationTemplate}"
                             VerticalContentAlignment="Center"
                             Height="30">

                    </TextBox>
                </HeaderedContentControl>

                <CheckBox BorderBrush="#53a0cc" 
                          BorderThickness="2" 
                          Foreground="#ff6e6e6e"
                          Margin="5,0"
                          Content="تفعيل المجموعة" 
                          IsChecked="{Binding Path=Entity.IsEnabled}" 
                          Height="30"/>

                <HeaderedContentControl Header="ملاحظات">
                    <TextBox Text="{Binding Path=Entity.Notes, ValidatesOnDataErrors=True, NotifyOnValidationError=True, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                             TextWrapping="Wrap"
                             AcceptsReturn="True"
                             Height="90"/>
                </HeaderedContentControl>

                <HeaderedContentControl Header="تاريخ الإنشاء">
                    <DatePicker Text="{Binding Path=Entity.CreateDate, ValidatesOnDataErrors=True, NotifyOnValidationError=True, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" 
                                Height="30" Width="200"
                                HorizontalAlignment="Left"
                                VerticalContentAlignment="Center" />
                </HeaderedContentControl>
            </StackPanel>
            <!--<Label Content="إذا أردت إنشاء مجموعة جديدة\r\nقم بالضغط على زر جديد أولا."
                   VerticalContentAlignment="Center"
                   HorizontalContentAlignment="Center"
                   Background="White"
                   Opacity=".7"
                   Visibility="{Binding Path=Entity, Converter={StaticResource nullConverter}}" />-->
        </Grid>

        <!-- Footer -->
        <DockPanel Grid.Row="2" Height="46">
            <Scenarios:DeleteBar />
            <Scenarios:EntityNavigationBar HorizontalAlignment="Right" DockPanel.Dock="Right" />
        </DockPanel>
    </Grid>
</UserControl>
